<?php

/**
 * Description of XQL_Pager
 *
 * @author prometheus
 */
class XQL_Pager extends x10_GeneralClass
{
    public $total = 0;

	public $offset = 0;

	public $pageSize = 0;

	public $pageNumber = 0;

	/**
	 * A lapozáshoz létrehozott limit XQL objektum.
	 * @var XQL_Limit
	 */
	public $xqlLimit;

	public function __construct(x10_Config $config=NULL)
	{
		parent::__construct($config);

		$this->pageNumber = $this->config->getConfigKey('pageNumber');
		$this->pageSize = $this->config->getConfigKey('pageSize');

		$this->updatePager();
	}

	public function updatePager()
	{
		unset($this->xqlLimit);

		$this->pageNumber == (int)$this->pageNumber; // Fő a biztonság
		if ($this->pageNumber < 0)
		{
			$this->pageNumber = 0;
		}

		$this->offset = $this->pageNumber * $this->pageSize;

		$this->xqlLimit = XQL_Limit::create()->
			join(
				XQL_Number::create()->set($this->pageSize)
			)->
			join(
				XQL_Offset::create()->set($this->offset)
			);
	}
}
?>
